package com.d3works.apps.account.web;

import com.d3works.apps.account.db.Reimbursement;
import com.d3works.apps.account.db.repo.ReimbursementRepository;
import com.d3works.apps.account.exception.AccountExceptionMessage;
import com.d3works.apps.account.service.ReimbursementService;
import com.d3works.i18n.I18n;
import com.d3works.inject.Beans;
import com.d3works.rpc.ActionRequest;
import com.d3works.rpc.ActionResponse;
import com.google.inject.Singleton;

@Singleton
public class ReimbursementController {

  public void validateReimbursement(ActionRequest request, ActionResponse response) {

    Reimbursement reimbursement = request.getContext().asType(Reimbursement.class);
    Beans.get(ReimbursementService.class).updatePartnerCurrentRIB(reimbursement);

    if (reimbursement.getBankDetails() != null) {
      response.setValue("statusSelect", ReimbursementRepository.STATUS_VALIDATED);
    } else {
      response.setInfo(I18n.get(AccountExceptionMessage.REIMBURSEMENT_4));
    }
  }
}
